package com.li.utlis;

import com.li.domain.Dept;
import com.li.domain.Menu;

import java.util.ArrayList;
import java.util.List;

public class DeptUtil {

    /**
     * 递归集合
     * @param deptList
     * @return
     */
    public static List<Dept> recursion(List<Dept> deptList){
        List<Dept> depts=new ArrayList();
        //BeanUtils.copyProperties(a,b);
        for (Dept dept:deptList){
            if (dept.getParentId()==0 || dept.getParentId()==null){
                depts.add(dept);
            }else{
                boolean flag=true;
                for (Dept d:deptList){
                    if (d.getDeptId()==dept.getParentId()){
                        if (d.getDepts()==null){
                            d.setDepts(new ArrayList<Dept>());
                        }
                        d.getDepts().add(dept);
                        flag=false;
                    }
                }
                if (flag){
                    depts.add(dept);
                }
            }
        }
        return depts;
    }
}
